<template>
    <div id="app">
        <transition name="fade">
            <router-view class="cube-view"></router-view>
        </transition>
    </div>
</template>

<script>


    import {getConfig} from "./config";

    export default {
        name: 'App',
        data() {
            return {
                version: "1.0.31"
            }
        },
        mounted() {
            let config = getConfig();
            let url = config.rootUrl + "static/app.js?t" + new Date().getTime()
            this.loadCardInfo()
            // this.$store.commit("updateNewVersion",{new_version:true})
            this.$get(url).then((res) => {
                if (res.version != this.$store.state.version) {
                    this.$store.commit("updateNewVersion", {new_version: true})

                    this.$createDialog({
                        type: 'confirm',
                        title: '提示',
                        content: '检测到新的版本，请下载升级',
                        icon: 'cubeic-alert',
                        confirmBtn: {
                            text: '立即升级',
                        },
                        cancelBtn: {
                            text: '下次升级',
                        },
                        onConfirm: () => {
                            if (!cordova.InAppBrowser) {
                                return;
                            }
                            let down_url = res.ios
                            if (device.platform == "Android") {
                                down_url = res.android
                            }
                            cordova.InAppBrowser.open(down_url, '_system', 'location=no,toolbar=yes,toolbarposition=top,closebuttoncaption=关闭');

                        }
                    }).show()
                }
                console.log(res)

            }).catch((error) => {
                alert(error)
            })
        },
        methods: {
            loadCardInfo() {
                let config = getConfig();
                let url = config.rootUrl + "/static/carrange.js?t" + new Date().getTime()
                this.$get(url).then((res) => {
                    console.log(res)
                    this.$store.commit("updateCoordinate", {coordinate:res})
                    localStorage.setItem("coordinate",JSON.stringify(res))
                }).catch((error)=>{
                    let res = JSON.parse(localStorage.getItem("coordinate"))
                    this.$store.commit("updateCoordinate", {coordinate:res})

                })
            }
        }
    }
</script>

<style lang="less">

    html, body, #app {
        height: 100%;
        width: 100%;
        position: absolute;
        left: 0;
        top: 0;
    }

    html, body {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
        SimSun, sans-serif;
        width: 100%;
        height: 100%;
        background: #f0f0f0;
        margin: 0;
    }

    body {
        overflow-x: hidden
    }

    .cube-view {
        transform: translate3d(0, 0, 0);
    }

    .page-move-enter,
    .page-move-leave-active {
        transform: translate3d(100%, 0, 0)
    }

    .page-move-enter-active, .page-move-leave-active {
        transition: transform .3s
    }
</style>
